package com.ch.home.controller.userController;

import com.ch.home.bean.Message;
import com.ch.home.service.serviceImpl.userServiceImpl.MessageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;

/**
 * Created by CHEN on 2019/9/1.
 */
@RestController
@RequestMapping("/user/message")
public class MessageController {

    @Autowired
    MessageServiceImpl messageService;


    //    HashMap sendMessage(Message message);
    public HashMap<Object, Object> sendMessage(@RequestParam(required = false) Integer senderId,
                                               @RequestParam(required = false) Integer receiverId,
                                               @RequestParam(required = false) String messageContent
    ) {

        Message message = new Message(null, senderId, receiverId, messageContent, new Date(), 1);
        HashMap result = messageService.sendMessage(message);
        return result;
    }

    //    HashMap recieveMessage(Message message);
    public HashMap receiveMessage(@RequestParam(required = false) Integer senderId,
                                  @RequestParam(required = false) Integer receiverId) {
        Message message = new Message(null, senderId, receiverId, null, null,1);

        HashMap<Object, Object> result = messageService.receiveMessage(message);

        return result;
    }
//    HashMap getMessageHistory(Message message,int limit);

    public HashMap getMessageHistory(@RequestParam(required = false) Integer senderId,
                                     @RequestParam(required = false) Integer receiverId,
                                     @RequestParam(required = false) Integer page) {
        Message message = new Message(null, senderId, receiverId, null, null,null);
        HashMap<Object, Object> result = messageService.getMessageHistory(message, page);
        return result;
    }


}
